#!/bin/sh
file_rrd_name=$1
file_img_name=$2
/usr/local/rrdtool-1.2.15/bin/rrdtool graph $file_img_name/mem_day.png \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="Linux Memory Usage(day)" \
--rigid \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="bytes" \
DEF:a="$file_rrd_name/mem_totalswap":mem_totalswap:AVERAGE \
DEF:b="$file_rrd_name/mem_availswap":mem_availswap:AVERAGE \
DEF:c="$file_rrd_name/mem_totalreal":mem_totalreal:AVERAGE \
DEF:d="$file_rrd_name/mem_availreal":mem_availreal:AVERAGE \
CDEF:cdefa=a,1024,* \
CDEF:cdefe=b,1024,* \
CDEF:cdefi=c,1024,* \
CDEF:cdefbc=d,1024,* \
LINE2:cdefa#B1441E:"Memory TotalSwap"  \
GPRINT:cdefa:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefa:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefe#FFF200:"Memory AvailSwap"  \
GPRINT:cdefe:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefe:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefe:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefi#002A97:"Memory TotalReal"  \
GPRINT:cdefi:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefi:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefi:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefbc#7CB3F1:"Memory AvailReal"  \
GPRINT:cdefbc:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefbc:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefbc:MAX:"Maximum\:%8.2lf %s\n" 

/usr/local/rrdtool-1.2.15/bin/rrdtool graph $file_img_name/mem_weekly.png \
--imgformat=PNG \
--start=-604800 \
--end=-1800 \
--title="Linux Memory Usage(weekly)" \
--rigid \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="bytes" \
DEF:a="$file_rrd_name/mem_totalswap":mem_totalswap:AVERAGE \
DEF:b="$file_rrd_name/mem_availswap":mem_availswap:AVERAGE \
DEF:c="$file_rrd_name/mem_totalreal":mem_totalreal:AVERAGE \
DEF:d="$file_rrd_name/mem_availreal":mem_availreal:AVERAGE \
CDEF:cdefa=a,1024,* \
CDEF:cdefe=b,1024,* \
CDEF:cdefi=c,1024,* \
CDEF:cdefbc=d,1024,* \
LINE2:cdefa#B1441E:"Memory TotalSwap"  \
GPRINT:cdefa:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefa:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefe#FFF200:"Memory AvailSwap"  \
GPRINT:cdefe:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefe:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefe:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefi#002A97:"Memory TotalReal"  \
GPRINT:cdefi:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefi:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefi:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefbc#7CB3F1:"Memory AvailReal"  \
GPRINT:cdefbc:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefbc:AVERAGE:"Average\:%8.2lf %s"  \

/usr/local/rrdtool-1.2.15/bin/rrdtool graph $file_img_name/mem_monthly.png \
--imgformat=PNG \
--start=-2678400 \
--end=-7200 \
--title="Linux Memory Usage(monthly)" \
--rigid \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="bytes" \
DEF:a="$file_rrd_name/mem_totalswap":mem_totalswap:AVERAGE \
DEF:b="$file_rrd_name/mem_availswap":mem_availswap:AVERAGE \
DEF:c="$file_rrd_name/mem_totalreal":mem_totalreal:AVERAGE \
DEF:d="$file_rrd_name/mem_availreal":mem_availreal:AVERAGE \
CDEF:cdefa=a,1024,* \
CDEF:cdefe=b,1024,* \
CDEF:cdefi=c,1024,* \
CDEF:cdefbc=d,1024,* \
LINE2:cdefa#B1441E:"Memory TotalSwap"  \
GPRINT:cdefa:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefa:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefe#FFF200:"Memory AvailSwap"  \
GPRINT:cdefe:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefe:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefe:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefi#002A97:"Memory TotalReal"  \
GPRINT:cdefi:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefi:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefi:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefbc#7CB3F1:"Memory AvailReal"  \
GPRINT:cdefbc:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefbc:AVERAGE:"Average\:%8.2lf %s"  \

/usr/local/rrdtool-1.2.15/bin/rrdtool graph $file_img_name/mem_yearly.png \
--imgformat=PNG \
--start=-33053184 \
--end=-86400 \
--title="Linux Memory Usage(yearly)" \
--rigid \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="bytes" \
DEF:a="$file_rrd_name/mem_totalswap":mem_totalswap:AVERAGE \
DEF:b="$file_rrd_name/mem_availswap":mem_availswap:AVERAGE \
DEF:c="$file_rrd_name/mem_totalreal":mem_totalreal:AVERAGE \
DEF:d="$file_rrd_name/mem_availreal":mem_availreal:AVERAGE \
CDEF:cdefa=a,1024,* \
CDEF:cdefe=b,1024,* \
CDEF:cdefi=c,1024,* \
CDEF:cdefbc=d,1024,* \
LINE2:cdefa#B1441E:"Memory TotalSwap"  \
GPRINT:cdefa:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefa:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefe#FFF200:"Memory AvailSwap"  \
GPRINT:cdefe:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefe:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefe:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefi#002A97:"Memory TotalReal"  \
GPRINT:cdefi:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefi:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefi:MAX:"Maximum\:%8.2lf %s\n"  \
LINE2:cdefbc#7CB3F1:"Memory AvailReal"  \
GPRINT:cdefbc:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefbc:AVERAGE:"Average\:%8.2lf %s"  \
